#include "StdAfx.h"
#include "SLineChart.h"


namespace SOUI
{
	SLineChart::SLineChart(void)
	{
	}

	SLineChart::~SLineChart(void)
	{

	}

	void SLineChart::DrawCurve(SGdip &gdip,std::vector<Point>& pts,DWORD color,int lineWid)
	{
		gdip.path_AddCurve(pts);
		gdip.draw_Path(color,lineWid);
		gdip.path_Clear();
		gdip.path_AddEllipse(pts,2);
		gdip.fill_Path(RGBA(0,0,0,255));
		gdip.draw_Path(color,lineWid);
		gdip.path_Clear();
	}

	void SLineChart::OnPaint(SOUI::IRenderTarget * pRT)
	{
		CRect wndRc=GetWindowRect();
		SGdip gdip(pRT,wndRc.left,wndRc.bottom-1);

		gdip.draw_x_rule(RGBA(128,128,128,255),100,660,4,2);
		gdip.draw_y_rule(RGBA(128,128,128,255),100,200,4,2);

		dataiteor ite=m_data.begin();
		for(;ite!=m_data.end();ite++)
		{
			DrawCurve(gdip,ite->second.list_data,ite->second.line_color,2);
		}
	}

	int SLineChart::GetMaxPointX(std::vector<Point> &pts)
	{
		std::vector<Point>::iterator ite=pts.begin();
		int retMax=INT_MIN;
		for(;ite!=pts.end();ite++)
		{
			retMax=max(ite->X,retMax);
		}
		return retMax;
	}

	int SLineChart::GetMaxPointY(std::vector<Point> &pts)
	{
		std::vector<Point>::iterator ite=pts.begin();
		int retMax=INT_MIN;
		for(;ite!=pts.end();ite++)
		{
			retMax=max(ite->Y,retMax);
		}
		return retMax;
	}

	HITTYPE SLineChart::HitTest(CPoint &pt)
	{		
		return OTHER;
	}

}
